﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;

namespace HtmlExtractor.Config
{
    public class RegexConfig
    {
        public string Expression
        { get; set; }
        private RegexOptions options = RegexOptions.None;
        public RegexConfig()
        { }
        /// <summary>
        /// regex不能为空
        /// </summary>
        /// <param name="regex"></param>
        public RegexConfig(XElement regex)
        {
            if (regex == null)
                throw new RequierdNotFindException(RequriedType.Element, "Regex");
            if (string.IsNullOrEmpty((string)regex))
            {
                throw new RequierdNotFindException(RequriedType.Text, "Regex");
            }
            Expression = (string)regex;
            Options = ((string)regex.Attribute("options")).ToRegexOptions();
        }
        /// <summary>
        /// 
        /// </summary>
        public RegexOptions Options
        {
            get { return options; }
            set { options = value; }
        }
        
    }
}
